import request from '_utils/request'
// 获取分类接口
const fetchCates = (params = {}) => request.get('/shop/goods/category/all', { params })
// 获取轮播图接口
const fetchHomeBanner = (params = {}) => request.get('/banner/list', { params })
// 获取商品列表
const fetchItems = (params = {}) => request.post('/shop/goods/list/v2', params)
// 获取商品详情数据
const fetchItemDetail = (id) => request.get('/shop/goods/detail', {
  params: {
    id
  }
})

// 注册
const doRegister = (params = {}) => request.post('/user/username/register', params)
// 登录
const doLogin = (params = {}) => request.post('/user/username/login', params)
// 加入购物车
const addCart = (params = {}) => request.post('/shopping-cart/add', params)
// 获取购物车数据
const fetchCartInfo = (params = {}) => request.get('/shopping-cart/info', { params })
// 修改商品数量
const setItemNum = (params = {}) => request.post('/shopping-cart/modifyNumber', params)
// 修改商品状态
const itemStateChange = (params = {}) => request.post('/shopping-cart/select', params)
// 删除购物车商品
const delItem = (params = {}) => request.post('/shopping-cart/remove', params)
// 添加收货地址
const addContact = (params = {}) => request.post('/user/shipping-address/add', params)
// 获取收获地址
const fetchAddress = (params = {}) => request.post('/user/shipping-address/list/v2', params)
// 获取单个地址详情
const getContactInfo = (params = {}) => request.get('/user/shipping-address/detail/v2', { params })
// 更新收获地址
const updateAddress = (params = {}) => request.post('/user/shipping-address/update', params)
// 删除收获地址
const delContact = (params = {}) => request.post('/user/shipping-address/delete', params)
// 创建订单
const createOrder = (query = {}) => request.post('/order/create', query)

// 获取用户详情
const fetUser = (params = {}) => request.get('/user/detail', { params })
// 上传文件
const upload = (query = {}) => request.post('/dfs/upload/file', query, {
  Headers: {
    'Content-Type': 'multipart/form-data'
  }
})
export {
  fetchCates,
  fetchHomeBanner,
  fetchItems,
  fetchItemDetail,
  doRegister,
  doLogin,
  addCart,
  fetchCartInfo,
  setItemNum,
  itemStateChange,
  delItem,
  addContact,
  fetchAddress,
  getContactInfo,
  updateAddress,
  delContact,
  createOrder,
  fetUser,
  upload
}
